package com.datoucai.utils;

import com.alibaba.fastjson.JSON;
import com.datoucai.dto.NotificationExtendDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Slf4j
public class NotificationExtendUtils {

    public static String buildExtend(String title,String link){
        NotificationExtendDto notificationExtendDto = new NotificationExtendDto();
        notificationExtendDto.setTitle(title);
        notificationExtendDto.setLink(link);
        return JSON.toJSONString(notificationExtendDto);
    }
    public static String getTitleOnExtend(String extend){
        if(StringUtils.isBlank(extend)){
            return null;
        }
        try {
            NotificationExtendDto notificationExtendDto = JSON.parseObject(extend, NotificationExtendDto.class);
            return notificationExtendDto.getTitle();
        } catch (Exception e) {
            log.error("标题-解析通知扩展信息异常",e);
            return null;
        }
    }
    public static String getLinkOnExtend(String extend){
        if(StringUtils.isBlank(extend)){
            return null;
        }
        try {
            NotificationExtendDto notificationExtendDto = JSON.parseObject(extend, NotificationExtendDto.class);
            return notificationExtendDto.getLink();
        } catch (Exception e) {
            log.error("链接-解析通知扩展信息异常",e);
            return null;
        }
    }
}
